package nextfm.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="tipo",discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue(value="U")
public abstract class Usuario {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique=true, nullable=false)
	private int id;
	
	@Column(nullable=false, length=255)
	private String nome;
	
	@Column(nullable=false, length=255, unique=true)
	private String login;
	
	@Column(nullable=false, length=255)
	private String senha;
	
	@Column(nullable=false, length=255)
	private String email;
	
	@OneToMany(mappedBy="usuario", cascade=CascadeType.ALL)
	private List<Comentario> comentarios = new ArrayList<Comentario>();
	
	public Usuario() {
		
	}

	public Usuario(String nome, String login, String senha, String email) {
		
		this.nome = nome;
		this.login = login;
		this.senha = senha;
		this.email = email;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<Comentario> getComentarios() {
		return comentarios;
	}

	public void setComentarios(List<Comentario> comentarios) {
		this.comentarios = comentarios;
	}
	
	public void addComentario(Comentario comentario) {
		this.comentarios.add(comentario);
	}
	
	public void removeComentario(Comentario comentario) {
		this.comentarios.remove(comentario);
	}
	
	@Override
	public String toString() {
		return "USUARIO:\nNome: " + getNome() + "\nLogin: " + getLogin() + "\nE-mail: " + getEmail();
	}
	
}
